cmake_minimum_required(VERSION 3.12.5)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/third_party/vcpkg/scripts/buildsystems/vcpkg.cmake)
set(VCPKG_TARGET_TRIPLET x64-linux CACHE STRING "vcpkg triplet")

project(qengine)
include_directories(
  ${CMAKE_SOURCE_DIR}/third_party/quickjspp
)

# 设置属性
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# enable asan
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")


set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin/${PROJECT_ARCH})
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin/${PROJECT_ARCH})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${PROJECT_ARCH})

file(GLOB _HEADE_FILES CONFIGURE_DEPENDS "src/*.h")
source_group("Header Files" FILES ${_HEADER_FILES})
file(GLOB _SOURCE_FILES CONFIGURE_DEPENDS "src/*.cpp")
source_group("Source Files" FILES ${_SOURCE_FILES})

file(GLOB _JSE_HEADE_FILES CONFIGURE_DEPENDS "src/jse/*.h")
source_group("JSE Header Files" FILES ${_JSE_HEADE_FILES})
file(GLOB _JSE_SOURCE_FILES CONFIGURE_DEPENDS "src/jse/*.cpp")
source_group("JSE Source Files" FILES ${_JSE_SOURCE_FILES})

file(GLOB _JSE_MODULES_HEADE_FILES CONFIGURE_DEPENDS "src/jse/modules/*.h")
source_group("JSE Header Files" FILES ${_JSE_MODULES_HEADE_FILES})
file(GLOB _JSE_MODULES_SOURCE_FILES CONFIGURE_DEPENDS "src/jse/modules/*.cpp")
source_group("JSE Source Files" FILES ${_JSE_MODULES_SOURCE_FILES})


find_package(imgui CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(uvw CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)

add_subdirectory(third_party/quickjspp EXCLUDE_FROM_ALL)
add_subdirectory(src/jse/js)
add_subdirectory(src/jse/modules)

include_directories(
  ${quickjs_sources_root}
)

add_executable(${PROJECT_NAME}
  ${_HEADE_FILES}
  ${_SOURCE_FILES}
  ${_JSE_HEADE_FILES}
  ${_JSE_SOURCE_FILES}
  ${_JSE_MODULES_HEADE_FILES}
  ${_JSE_MODULES_SOURCE_FILES}
)

target_link_libraries(${PROJECT_NAME} PRIVATE
  imgui::imgui
  glfw
  quickjs
  uvw::uvw
  spdlog::spdlog spdlog::spdlog_header_only
  qjscode
  jse_module_glue
)
